package com.kejiguan.ui.adapter;

import android.content.Context;
import android.database.DataSetObserver;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.SpinnerAdapter;
import android.widget.TextView;

import com.kejiguan.ui.R;

/**
 * Created by apple on 16/5/12.
 */
public class TimeSpinnerAdapter implements SpinnerAdapter{

    private LayoutInflater inflater;
    private int min,max;

    public TimeSpinnerAdapter(Context context,int min,int max)
    {
        inflater=LayoutInflater.from(context);
        this.min=min;
        this.max=max;
    }

    @Override
    public View getDropDownView(int position, View convertView, ViewGroup parent) {
        View itemView=inflater.inflate(R.layout.dialog_time_select_dropdown_item_view,null);
        TextView timeView= (TextView) itemView.findViewById(R.id.time_name);
        int value=min+position;
        if (value<10)
        {
            timeView.setText("0"+value);
        }else
        {
            timeView.setText(String.valueOf(value));
        }

        return itemView;
    }

    @Override
    public void registerDataSetObserver(DataSetObserver observer) {

    }

    @Override
    public void unregisterDataSetObserver(DataSetObserver observer) {

    }

    @Override
    public int getCount() {
        return (max-min)+1;
    }

    @Override
    public Object getItem(int position) {
        return null;
    }

    @Override
    public long getItemId(int position) {
        return min+position;
    }

    @Override
    public boolean hasStableIds() {
        return false;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {

        View itemView=inflater.inflate(R.layout.dialog_time_select_item_view,null);
        TextView timeView= (TextView) itemView.findViewById(R.id.time_name);
        int value=min+position;
        if (value<10)
        {
            timeView.setText("0"+value);
        }else
        {
            timeView.setText(String.valueOf(value));
        }

        return itemView;
    }

    @Override
    public int getItemViewType(int position) {
        return 0;
    }

    @Override
    public int getViewTypeCount() {
        return 1;
    }

    @Override
    public boolean isEmpty() {
        return false;
    }
}
